package zj.xinxin.web.controller.article;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zj.xinxin.api.moudle.article.api.DiscussService;
import zj.xinxin.api.moudle.article.dto.DiscussDto;
import zj.xinxin.api.moudle.article.vo.DiscussVo;
import zj.xinxin.common.result.ResponseResult;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 评论  前端控制器
 * </p>
 *
 * @author zhoujun
 * @since 2022-04-12
 */
@RestController
@Api(tags = "评论信息")
@RequestMapping("/article/discuss")
public class DiscussController {

    @Autowired
    DiscussService discussService;

    @PostMapping("/add")
    @ApiOperation(value = "添加评论信息")
    public ResponseResult<Boolean> add(@RequestBody @Valid DiscussVo discuss) {

        return discussService.saveDiscuss(discuss) ?
                ResponseResult.success("添加成功", true ):
                ResponseResult.fail("保存失败", false);
    }

    @GetMapping("/get/{articleId}")
    @ApiOperation(value = "获取文章的评论信息")
    public ResponseResult<List<DiscussDto>> get(@PathVariable("articleId") Long articleId) {
        return ResponseResult.success("保存成功", discussService.getByArticleId(articleId));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除评论")
    public ResponseResult<Boolean> delete(@PathVariable("id") Long id) {

        return discussService.removeById(id) ?
                ResponseResult.success("删除成功", true ):
                ResponseResult.fail("删除失败", false);
    }
}

